package cn.kshost.zqyg.manager.service.impl;

import cn.kshost.zqyg.manager.mapper.OrderStatisticsMapper;
import cn.kshost.zqyg.manager.service.OrderStatisticsService;
import cn.kshost.zqyg.model.dto.order.OrderStatisticsDto;
import cn.kshost.zqyg.model.entity.order.OrderStatistics;
import cn.kshost.zqyg.model.vo.order.OrderStatisticsVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

@Service
public class OrderStatisticsServiceImpl implements OrderStatisticsService {
    @Autowired
    private OrderStatisticsMapper orderStatisticsMapper;
    @Override
    public OrderStatisticsVo getOrderStatisticsData(OrderStatisticsDto orderStatisticsDto) {
        List<OrderStatistics> orderStatisticsList =  orderStatisticsMapper.selectOrderStatisticsData(orderStatisticsDto);
        OrderStatisticsVo orderStatisticsVo = new OrderStatisticsVo();
        orderStatisticsVo.setAmountList(new ArrayList<BigDecimal>());
        orderStatisticsVo.setDateList(new ArrayList<String>());

        orderStatisticsList.forEach(
                orderStatistics -> {
                    //格式化时间

                    String format = new SimpleDateFormat("yyyy-MM-dd").format(orderStatistics.getOrderDate());
                    orderStatisticsVo.getDateList().add(format);
                    orderStatisticsVo.getAmountList().add(orderStatistics.getTotalAmount());
                }
        );
        return orderStatisticsVo;
    }
}
